﻿Imports System.Data.SqlClient

Public Class ChiTietPhimDAO
    Public Shared Sub xoaCTPhim(ByVal ctphim As ChiTietPhimDTO)
        Dim sql As String = "delete from CHITIETPHIM where MaPhim='" + ctphim.maPhim + "' and DaoDien=N'" + ctphim.daoDien + _
            "' and NamSanXuat=" + ctphim.namSanXuat.ToString() + ""
        DataProvider.ExcuteQuery(sql)
    End Sub

    Public Shared Sub xoaTatCa(ByVal ctphim As ChiTietPhimDTO)
        Dim sql As String = "delete from CHITIETPHIM where MaPhim='" + ctphim.maPhim + "'
        DataProvider.ExcuteQuery(sql)
    End Sub

    Public Shared Function testCTPhim(ByVal ctphim As ChiTietPhimDTO)
        Dim cn As New SqlConnection
        cn = DataProvider.CreaConnection()
        Dim cmd As New SqlCommand("sp_testCTPhim", cn)
        cmd.CommandType = CommandType.StoredProcedure

        Dim input As New SqlParameter("@maphim", SqlDbType.VarChar)
        Dim output As New SqlParameter("@flag", SqlDbType.Bit)

        input.Size = 20
        input.Value = ctphim.maPhim
        output.Direction = ParameterDirection.Output

        cmd.Parameters.Add(input)
        cmd.Parameters.Add(output)

        cmd.ExecuteNonQuery()

        Dim flag As Boolean
        flag = Convert.ToBoolean(output.Value)
        cn.Close()
        Return flag
    End Function

    Public Shared Sub ThemCTPhim(ByVal ctphim As ChiTietPhimDTO)
        Dim sql As String = "insert into CHITIETPHIM(MaPhim,DaoDien,NamSanXuat,QuocGia,ThoiLuong,HinhAnh,NgayNhap) values('" + ctphim.maPhim + _
            "',N'" + ctphim.daoDien + "'," + ctphim.namSanXuat.ToString() + ",N'" + ctphim.quocGia + "'," + ctphim.thoiLuong.ToString() + ",'" + ctphim.hinhAnh + "',getdate())"
        DataProvider.ExcuteQuery(sql)
    End Sub

    Public Shared Sub updateCTPhim(ByVal ctphim As ChiTietPhimDTO)
        Dim sql As String = "update CHITIETPHIM set DaoDien=N'" + ctphim.daoDien + "', NamSanXuat=" + ctphim.namSanXuat.ToString() + _
            " ,QuocGia=N'" + ctphim.quocGia + "',ThoiLuong=" + ctphim.thoiLuong.ToString() + " ,HinhAnh='" + ctphim.hinhAnh + "',NgayNhap='" + ctphim.ngayNhap.ToShortDateString() + "' where MaPhim='" + ctphim.maPhim + "'"
        DataProvider.ExcuteQuery(sql)
    End Sub

    Public Shared Function loadCTPhim(ByVal ctphim As ChiTietPhimDTO) As DataTable
        Dim sql As String = "select * from CHITIETPHIM where MaPhim='" + ctphim.maPhim + "'"
        Dim dt As New DataTable
        dt = DataProvider.DataTable(sql)
        Return dt
    End Function
    
End Class
